<template>
  <div class="share_card">
    <el-dialog
        custom-class="choose_dialog"
        :visible.sync="shareCardState"
        width="840px"
        :show-close="false"
        :close-on-click-modal="false">
        <div class="dialog_top">
            <div class="dialog_title">创建群聊</div>
            <img class="cancel_dialog_btn" src="../../assets/icons/icon_close_up.png" @click="cancelDialog" />
        </div>

        <div class="choose_box">
          <div class="all_members">
            <div class="member_search">
              <div class="search_content">
                  <img class="search_icon" src="../../assets/icons/icon_search.png"/>
                  <input class="search_input" type="text" placeholder="输入昵称" maxlength="30" v-model="memberText"/>
              </div>
            </div>

            <ul class="friends_box">
              <li class="friends_line" v-for="(data,index) in list" :key="index" @click="chooseFriend(data)">
                <img class="friends_avatar" :src="data.img" />
                <span class="friends_name">{{data.name}}</span>
                <img class="choose_icon" v-show="!data.choose" src="../../assets/choose.png" />
                <img class="choose_icon" v-show="data.choose" src="../../assets/choosed.png" />
              </li>
            </ul>
          </div>

          <div class="all_choosed">
            <div class="card_box">
              <div class="card_text">分享该好友</div>
              <div class="card_detail">
                <img class="card_avatar" src="../../assets/test_avatar.jpg">
                <span class="card_nick">爱因斯坦</span>
              </div>
            </div>

            <div class="choosed_top">
              <div class="choosed_tips">分别发送给已选聊天<span v-show="choosedList.length!=0">({{choosedList.length}})</span></div>
            </div>
            
            <ul class="choosed_list">
              <li class="choosed_member" v-for="(item,index) in choosedList" :key="index">
                <img class="choosed_avatar" :src="item.img" />
                <div class="choosed_name">{{item.name}}</div>
                <img class="cancel_choosed" src="../../assets/icons/icon_delete_up.png" @click="cancelChoosed(item,index)" />
              </li>
            </ul>
          </div>
        </div>

        <div class="btns">
          <div :class="['primarybtn',{'disabled':choosedList.length==0}]">转发</div>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import {Dialog} from 'element-ui'
export default {
  name:'share_card',
  data(){
      return {
        searchText:'',
        memberText:'',
        choosedList:[],
        list:
        [
          {
            choose:false,
            img:'https://thirdwx.qlogo.cn/mmopen/vi_32/OQD4fMO3kYuJxibwZzlXy7cKs0Ech85xj7nAeHgFIA2sXJRkHFfaXhkia0WbyCmtzpmhPuJMbAwWPRu2VqVvnnBQ/132',
            name:'测试',
            id:1
          },
          {
            choose:false,
            img:'https://thirdwx.qlogo.cn/mmopen/vi_32/OQD4fMO3kYuJxibwZzlXy7cKs0Ech85xj7nAeHgFIA2sXJRkHFfaXhkia0WbyCmtzpmhPuJMbAwWPRu2VqVvnnBQ/132',
            name:'猫',
            id:2
          },
          {
            choose:false,
            img:'https://thirdwx.qlogo.cn/mmopen/vi_32/OQD4fMO3kYuJxibwZzlXy7cKs0Ech85xj7nAeHgFIA2sXJRkHFfaXhkia0WbyCmtzpmhPuJMbAwWPRu2VqVvnnBQ/132',
            name:'测试',
            id:3
          },
          {
            choose:false,
            img:'https://thirdwx.qlogo.cn/mmopen/vi_32/OQD4fMO3kYuJxibwZzlXy7cKs0Ech85xj7nAeHgFIA2sXJRkHFfaXhkia0WbyCmtzpmhPuJMbAwWPRu2VqVvnnBQ/132',
            name:'猫',
            id:4
          }
        ]
      }
  },
  props:{
    shareCardState:Boolean
  },
  components: {
      'el-dialog':Dialog
  },
  mounted(){
    
  },
  methods:{
    cancelDialog(){
      this.searchText = ''
      this.$emit('changeShareCardState',false)
    },
    //选择好友
    chooseFriend(data){
      this.list.forEach((element)=>{
        if(element.id==data.id){
          if(data.choose){
            this.$set(element,'choose',false)
            this.choosedList.forEach((content,i)=>{
              if(data.id==content.id){
                this.choosedList.splice(i,1)
              }
            })
          }else{
            this.$set(element,'choose',true)
            this.choosedList.push(data)
          }
        }
      })
    },
    //取消选择
    cancelChoosed(data,index){
      this.list.forEach((element)=>{
        if(element.id==data.id){
          this.$set(element,'choose',false)
        }
      })
      this.choosedList.splice(index,1)
    }
  }
}
</script>

<style scoped>
.dialog_top{
    display: flex;
    align-items: center;
    justify-content: space-between;
    line-height: 42px;
    padding: 0 25px 0 30px;
}
.cancel_dialog_btn{
    width:24px;
    height:24px;
    cursor: pointer;
}
.member_search{
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.member_search .search_icon{
    padding:0px 8px;
}
.search_input{
    min-width:280px;
    color: #428dfc;
    line-height: 30px;
    border:none;
}
.search_icon{
    width:20px;
}

.choose_box{
  display: flex;
  padding:0px 30px 0px;
}
.all_members{
  width: 360px;
  margin-right: 30px;
}
.friends_box{
  height:360px;
  overflow: auto;
}
.pingyin_first{
  font-size: 12px;
  line-height: 20px;
  background: #fcfcfc;
}
.friends_avatar{
  width:34px;
  height:34px;
}
.friends_line{
  padding: 10px 0;
  height: 54px;
  cursor: pointer;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}
.friends_name{
  padding:0 10px;
  flex:1;
}
.choose_icon{
  width:18px;
}
.all_choosed{
  flex:1;
}



.card_box{
  padding: 0 10px;
  border: 1px solid #f1f1f1;
  border-radius: 4px;
}
.card_text{
  line-height: 40px;
  border-bottom: 1px solid #f1f1f1;
}
.card_detail{
  display: flex;
  align-items: center;
  padding: 10px 0;
}
.card_avatar{
  width:60px;
  height: 60px;
  margin-right:10px;
}
.card_nick{
  font-size: 14px;
  color: #333;
}
.choosed_top{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.choosed_tips{
  flex:1;
  height:40px;
  line-height: 40px;
}

.choosed_list{
  height:228px;
  overflow: auto;
}
.choosed_member{
  padding: 10px 0;
  height: 54px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}
.choosed_avatar{
  width:34px;
  height:34px;
}
.choosed_name{
  padding:0 10px;
  flex:1;
}
.cancel_choosed{
  width:18px;
  height:18px;
  cursor: pointer;
}
.btns{
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px 30px 50px;
}
</style>